//
//  CYTrendBottomView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/8/23.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYTrendBottomView.h"
@interface CYTrendBottomView(){
    trendBlock _myblock;
}
@property (nonatomic, strong) CYButton *button;
@property (nonatomic, strong) CYLabel *dateLBL;
@property (nonatomic, strong) CYLabel *timeLBL;
@end
@implementation CYTrendBottomView
- (instancetype)initWithColor:(UIColor *)color line:(LineLayout)layout lineColor:(UIColor *)linecolor block:(trendBlock)block{
    self = [super initWithColor:color line:layout lineColor:linecolor];
    if (self) {
        _myblock = block;
        self.button.hidden = self.dateLBL.hidden = NO;
        self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, AUTO(44));
        self.lineWidth = 0.5;
    }
    return self;
}

- (CYButton *)button{
    if (!_button) {
        _button = [[CYButton alloc]initWithTitle:@"立即选号" titleColor:[UIColor whiteColor] backgroundColor:THEME_COLOR cornerRadius:5];
        [_button addTarget:self action:@selector(chooseNumber) forControlEvents:UIControlEventTouchUpInside];
        _button.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_button];
        
        [_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(- 10);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(AUTO(88), 33));
        }];
    }
    return _button;
}

- (CYLabel *)dateLBL{
    if (!_dateLBL) {
        _dateLBL = [[CYLabel alloc]initWithText:[NSString stringWithFormat:@"距%@截止:",_date] size:(IS_IPHONE_5_)?12:14 textcolor:ColorHex(0x333333)];
        [self addSubview:_dateLBL];
        
        [_dateLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(10);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(_dateLBL.bounds.size);
        }];
    }
    return _dateLBL;
}

- (CYLabel *)timeLBL{
    if (!_timeLBL) {
        _timeLBL = [[CYLabel alloc]initWithText:nil size:14 textcolor:THEME_COLOR];
        [self addSubview:_timeLBL];
        
        [_timeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_dateLBL.mas_right).with.offset(10);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(_timeLBL.bounds.size);
        }];
    }
    return _timeLBL;
}

- (void)setDate:(NSString *)date{
    if (_date != date)
        _date = date;
    self.dateLBL.text = [NSString stringWithFormat:@"距%@期截止:",date];
    
    [_dateLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_dateLBL.bounds.size);
    }];
    
}
- (void)setTime:(NSString *)time{
    if (_time != time)
        _time = time;
    self.timeLBL.text = time;
    
    [_timeLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_timeLBL.bounds.size);
    }];
}

- (void)chooseNumber{
    _myblock();
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
